#include <stdint.h>
#include <unistd.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h>
using namespace std;

class loggerTest {
private:
    shared_ptr<spdlog::logger> logger;
public:
    loggerTest()
    {
        uint32_t file_size = 1024 * 1024 * 5;
        uint32_t file_num = 3;
        string tag = "spdlog_test";
        string log_path = "test/test.log";
        logger = spdlog::rotating_logger_mt(tag, log_path, file_size, file_num);
        spdlog::set_default_logger(logger);
        spdlog::set_level(spdlog::level::debug); // 设置全局日志级别
        spdlog::set_pattern("[%Y%m%d-%H:%M:%S %n:%l] %v");
    }
    // 析构函数，用于清理loggerTest对象
    ~loggerTest()
    {
        // 从spdlog中删除名为"logger"的日志记录器
        spdlog::drop("logger");
        spdlog::shutdown();
    }
    void test_log()
    {
        int count = 10;
        while (count--)
        {
            spdlog::debug("spdlog count={}", count);
            // SPDLOG_LOGGER_INFO(logger, "this is test count={}", count);
            sleep(1);
        }
    }
};

int main(void)
{
    loggerTest logger;
    logger.test_log();

    return 0;
}
